#include"functions.h"

int main()
{
  double e = 0.0001;
  double a = 0.5;
  int n = 99;
  double h = 1.0/100;
  double** A = new double*[n];
  for(int i = 0; i < n; i++)
    A[i] = new double[n]();
  for(int i = 0; i < n; i++)
    { 
      A[i][i] = (-1)*(2*e + h);
      if(i != n-1)
	A[i+1][i] = e;
      if(i != 0)
	A[i-1][i] = e + h;
    }
  //输出精确解
  for(int i = 1; i <= n; i++)
    std::cout << "y[" << i << "] = "
    << (1-a)/(1-exp(-1.0/e))*(1-exp(-i*h/e))+a*i*h << std::endl;
  double* b = new double[n]();
  for(int i = 0; i < n-1 ;i++)
    b[i] = a*h*h;
  b[n-1] = a*h*h-(e+h)*1;
  double* x = new double[n]();;
  Jacobi_Iteration(A, b, x, pow(10,-10), n);
  for(int i = 0; i < n; i++)
    x[i] = 0.0;
  GS_Iteration(A, b, x, pow(10, -10), n);
  for(int i = 0; i < n; i++)
    x[i] = 0.0;
  double w = 1.0;
  SOR(A, b, x, w, pow(10, -10), n);
  
  for(int i = 0; i < n; i++)
    delete [] A[i];
  delete [] A;
  delete [] b;
  delete [] x;
  return 0;
};
